package com.sgb.kjwl.viewmodel.self.publish;

import androidx.databinding.ObservableField;

import com.swgk.core.base.api.ICallBack;
import com.sgb.kjwl.api.NewAPIManager;
import com.sgb.kjwl.model.entity.AddBrandEntity3;
import com.sgb.kjwl.repository.SelfRepertory;
import com.sgb.kjwl.view.ui.activity.self.publish.AddBrandActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.SharedPreferenceUtil;

import java.util.HashMap;
import java.util.Map;

public class AddBrandModel extends BaseViewModel {
    public ObservableField<AddBrandEntity3> brandEntity3 = new ObservableField<>(new AddBrandEntity3());
    private AddBrandActivity activity;
    private SelfRepertory repertory;
    private int page = 1;
    private int size = 20;
    public int total;

    public AddBrandModel(AddBrandActivity activity, SelfRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }


    public void saveBrand() {
        String companyId = SharedPreferenceUtil.getInstance().getSaveStringData(com.swgk.core.util.SharedPreferenceUtil.REAL_ID, "");
        brandEntity3.get().setCompanyId(companyId);
        DialogHelper.showProgressDialog(activity, null, "数据上传中...", 0, false, null).setCanceledOnTouchOutside(false);
        Map<String, Object> data = new HashMap<>();
        data.put("companyId", companyId);
        data.put("id", brandEntity3.get().getId());
        data.put("brandName", brandEntity3.get().getBrandName());
        data.put("mark", brandEntity3.get().getMark());
        data.put("cid3", brandEntity3.get().getCid3());
        NewAPIManager.getInstance().getGoodsReleasedAPI().saveBrand(data).enqueue(new ICallBack<BaseEntity<Object>>() {
            @Override
            public void onSuccess(BaseEntity<Object> data) {
                activity.showSuccess();
            }
        });
    }

    public String getNo() {
        return repertory.getNo();
    }
}
